package com.sgb.kjwl.view.ui.adapter.self.packers;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.SelfTeamProjectEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

public class SelfTeamProjectAdapter extends BaseRecycleAdapter<SelfTeamProjectEntity> {

    private Button editView;
    private Button delView;
    private TextView timeView;
    private TextView addressView;
    private TextView typeView;
    private ItemCallBack itemCallBack;

    public SelfTeamProjectAdapter(Context context, List<SelfTeamProjectEntity> datas) {
        super(context, R.layout.item_self_team_project, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfTeamProjectEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        editView = holder.getItem().findViewById(R.id.btn_edit);
        delView = holder.getItem().findViewById(R.id.btn_delete);
        timeView = holder.getItem().findViewById(R.id.time_view);
        addressView = holder.getItem().findViewById(R.id.address_view);
        typeView = holder.getItem().findViewById(R.id.tv_team_type);
        editView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.edit(entity.getNo());
                }
            }
        });
        delView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemCallBack != null) {
                    itemCallBack.del(entity.getNo());
                }
            }
        });
        timeView.setText(DateUtils.timestampToDate(entity.getCreateTime()));
    }

    public void setItemCallBack(ItemCallBack itemCallBack) {
        this.itemCallBack = itemCallBack;
    }

    public interface ItemCallBack {
        void del(String id);

        void edit(String no);
    }
}
